/**
 *
 */
package com.wedroid.r2d2.message;

import java.util.Date;

import com.wedroid.entity.message.MessageType;
import com.wedroid.r2d2.contact.Contact;

/**
 * @author lute
 *
 */
public class RipeMessage {

    private String msgId;

    private Contact sender;

    private String senderDisplayName;

    private Contact receiver;

    private String receiverDisplayName;

    private Contact fromUser;

    private String fromUserDisplayName;

    private MessageType messageType;

    private Date createTime;

    private String data;

    private Contact droid;

    /**
     * @param builder
     */
    private RipeMessage(RipeMessageBuilder builder) {
        this.msgId = builder.msgId;
        this.sender = builder.sender;
        this.senderDisplayName = builder.senderDisplayName;
        this.receiver = builder.receiver;
        this.receiverDisplayName = builder.receiverDisplayName;
        this.fromUser = builder.fromUser;
        this.fromUserDisplayName = builder.fromUserDisplayName;
        this.messageType = builder.messageType;
        this.createTime = builder.createTime;
        this.data = builder.data;
        this.droid = builder.droid;
    }

    public static class RipeMessageBuilder {

        private String msgId;
        private Contact sender;
        private String senderDisplayName;
        private Contact receiver;
        private String receiverDisplayName;
        private Contact fromUser;
        private String fromUserDisplayName;
        private MessageType messageType;
        private Date createTime;
        private String data;
        private Contact droid;

        /**
         * @param msgId
         * @param type
         * @param elapsedSeconds
         */
        public RipeMessageBuilder(String msgId, MessageType type, long elapsedSeconds) {
            this.msgId = msgId;
            this.messageType = type;
            this.createTime = new Date(elapsedSeconds * 1000);
        }

        /**
         * @param sender
         * @param senderDisplayName
         * @return
         */
        public RipeMessageBuilder sender(Contact sender, String senderDisplayName) {
            this.sender = sender;
            this.senderDisplayName = senderDisplayName;
            return this;
        }

        /**
         * @param receiver
         * @param receiverDisplayName
         * @return
         */
        public RipeMessageBuilder receiver(Contact receiver, String receiverDisplayName) {
            this.receiver = receiver;
            this.receiverDisplayName = receiverDisplayName;
            return this;
        }

        /**
         * @param fromUser
         * @return
         */
        public RipeMessageBuilder fromUser(Contact fromUser) {
            this.fromUser = fromUser;
            this.fromUserDisplayName = fromUser.getPreferredName();
            return this;
        }

        /**
         * @param data
         * @return
         */
        public RipeMessageBuilder data(String data) {
            this.data = data;
            return this;
        }

        /**
         * @param droid
         * @return
         */
        public RipeMessageBuilder droid(Contact droid) {
            this.droid = droid;
            return this;
        }

        /**
         * @return
         */
        public RipeMessage build() {
            return new RipeMessage(this);
        }

    }

    /**
     * @return the msgId
     */
    public String getMsgId() {
        return msgId;
    }

    /**
     * @return the sender
     */
    public Contact getSender() {
        return sender;
    }

    /**
     * @return the senderDisplayName
     */
    public String getSenderDisplayName() {
        return senderDisplayName;
    }

    /**
     * @return the receiver
     */
    public Contact getReceiver() {
        return receiver;
    }

    /**
     * @return the receiverDisplayName
     */
    public String getReceiverDisplayName() {
        return receiverDisplayName;
    }

    /**
     * @return the fromUser
     */
    public Contact getFromUser() {
        return fromUser;
    }

    /**
     * @return the fromUserDisplayName
     */
    public String getFromUserDisplayName() {
        return fromUserDisplayName;
    }

    /**
     * @return the messageType
     */
    public MessageType getMessageType() {
        return messageType;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the data
     */
    public String getData() {
        return data;
    }

    /**
     * @return the droid
     */
    public Contact getDroid() {
        return droid;
    }

}
